home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SAMPLES / VISDATA / DYNASNAP.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-07  |  34.0 KB  |  1,016 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDynaSnap 
  3.    ClientHeight    =   3750
  4.    ClientLeft      =   2730
  5.    ClientTop       =   2610
  6.    ClientWidth     =   5490
  7.    HelpContextID   =   2016125
  8.    Icon            =   "DYNASNAP.frx":0000
  9.    KeyPreview      =   -1  'True
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3733.906
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   5503.698
  16.    ShowInTaskbar   =   0   'False
  17.    Tag             =   "Recordset"
  18.    Begin VB.PictureBox picViewButtons 
  19.       Align           =   1  'Align Top
  20.       Appearance      =   0  'Flat
  21.       BorderStyle     =   0  'None
  22.       ForeColor       =   &H80000008&
  23.       Height          =   852
  24.       Left            =   0
  25.       ScaleHeight     =   855
  26.       ScaleMode       =   0  'User
  27.       ScaleWidth      =   5487.272
  28.       TabIndex        =   13
  29.       TabStop         =   0   'False
  30.       Top             =   0
  31.       Width           =   5484
  32.       Begin VB.CommandButton cmdMove 
  33.          Caption         =   "&Move"
  34.          BeginProperty Font 
  35.             Name            =   "Tahoma"
  36.             Size            =   8.25
  37.             Charset         =   0
  38.             Weight          =   400
  39.             Underline       =   0   'False
  40.             Italic          =   0   'False
  41.             Strikethrough   =   0   'False
  42.          EndProperty
  43.          Height          =   345
  44.          Left            =   2730
  45.          MaskColor       =   &H00000000&
  46.          TabIndex        =   7
  47.          Top             =   375
  48.          Width           =   1365
  49.       End
  50.       Begin VB.CommandButton cmdSort 
  51.          Caption         =   "&Sort"
  52.          BeginProperty Font 
  53.             Name            =   "Tahoma"
  54.             Size            =   8.25
  55.             Charset         =   0
  56.             Weight          =   400
  57.             Underline       =   0   'False
  58.             Italic          =   0   'False
  59.             Strikethrough   =   0   'False
  60.          EndProperty
  61.          Height          =   345
  62.          Left            =   0
  63.          MaskColor       =   &H00000000&
  64.          TabIndex        =   5
  65.          Top             =   372
  66.          Width           =   1365
  67.       End
  68.       Begin VB.CommandButton cmdFilter 
  69.          Caption         =   "F&ilter"
  70.          BeginProperty Font 
  71.             Name            =   "Tahoma"
  72.             Size            =   8.25
  73.             Charset         =   0
  74.             Weight          =   400
  75.             Underline       =   0   'False
  76.             Italic          =   0   'False
  77.             Strikethrough   =   0   'False
  78.          EndProperty
  79.          Height          =   345
  80.          Left            =   1365
  81.          MaskColor       =   &H00000000&
  82.          TabIndex        =   6
  83.          Top             =   375
  84.          Width           =   1365
  85.       End
  86.       Begin VB.CommandButton cmdClose 
  87.          Cancel          =   -1  'True
  88.          Caption         =   "&Close"
  89.          BeginProperty Font 
  90.             Name            =   "Tahoma"
  91.             Size            =   8.25
  92.             Charset         =   0
  93.             Weight          =   400
  94.             Underline       =   0   'False
  95.             Italic          =   0   'False
  96.             Strikethrough   =   0   'False
  97.          EndProperty
  98.          Height          =   345
  99.          Left            =   4095
  100.          MaskColor       =   &H00000000&
  101.          TabIndex        =   4
  102.          TabStop         =   0   'False
  103.          Top             =   15
  104.          Width           =   1365
  105.       End
  106.       Begin VB.CommandButton cmdDelete 
  107.          Caption         =   "&Delete"
  108.          BeginProperty Font 
  109.             Name            =   "Tahoma"
  110.             Size            =   8.25
  111.             Charset         =   0
  112.             Weight          =   400
  113.             Underline       =   0   'False
  114.             Italic          =   0   'False
  115.             Strikethrough   =   0   'False
  116.          EndProperty
  117.          Height          =   345
  118.          Left            =   2730
  119.          MaskColor       =   &H00000000&
  120.          TabIndex        =   3
  121.          Top             =   15
  122.          Width           =   1365
  123.       End
  124.       Begin VB.CommandButton cmdEdit 
  125.          Caption         =   "&Edit"
  126.          BeginProperty Font 
  127.             Name            =   "Tahoma"
  128.             Size            =   8.25
  129.             Charset         =   0
  130.             Weight          =   400
  131.             Underline       =   0   'False
  132.             Italic          =   0   'False
  133.             Strikethrough   =   0   'False
  134.          EndProperty
  135.          Height          =   345
  136.          Left            =   1365
  137.          MaskColor       =   &H00000000&
  138.          TabIndex        =   2
  139.          Top             =   15
  140.          Width           =   1365
  141.       End
  142.       Begin VB.CommandButton cmdAdd 
  143.          Caption         =   "&Add"
  144.          BeginProperty Font 
  145.             Name            =   "Tahoma"
  146.             Size            =   8.25
  147.             Charset         =   0
  148.             Weight          =   400
  149.             Underline       =   0   'False
  150.             Italic          =   0   'False
  151.             Strikethrough   =   0   'False
  152.          EndProperty
  153.          Height          =   345
  154.          Left            =   0
  155.          MaskColor       =   &H00000000&
  156.          TabIndex        =   1
  157.          Top             =   20
  158.          Width           =   1365
  159.       End
  160.       Begin VB.CommandButton cmdFind 
  161.          Caption         =   "&Find"
  162.          BeginProperty Font 
  163.             Name            =   "Tahoma"
  164.             Size            =   8.25
  165.             Charset         =   0
  166.             Weight          =   400
  167.             Underline       =   0   'False
  168.             Italic          =   0   'False
  169.             Strikethrough   =   0   'False
  170.          EndProperty
  171.          Height          =   345
  172.          Left            =   4095
  173.          MaskColor       =   &H00000000&
  174.          TabIndex        =   8
  175.          Top             =   375
  176.          Width           =   1365
  177.       End
  178.    End
  179.    Begin VB.PictureBox picChangeButtons 
  180.       Appearance      =   0  'Flat
  181.       BorderStyle     =   0  'None
  182.       ForeColor       =   &H80000008&
  183.       Height          =   855
  184.       Left            =   0
  185.       ScaleHeight     =   919.528
  186.       ScaleMode       =   0  'User
  187.       ScaleWidth      =   5719.056
  188.       TabIndex        =   14
  189.       TabStop         =   0   'False
  190.       Top             =   0
  191.       Visible         =   0   'False
  192.       Width           =   5655
  193.       Begin VB.CommandButton cmdUpdate 
  194.          Caption         =   "&Update"
  195.          BeginProperty Font 
  196.             Name            =   "Tahoma"
  197.             Size            =   8.25
  198.             Charset         =   0
  199.             Weight          =   400
  200.             Underline       =   0   'False
  201.             Italic          =   0   'False
  202.             Strikethrough   =   0   'False
  203.          EndProperty
  204.          Height          =   372
  205.          Left            =   960
  206.          MaskColor       =   &H00000000&
  207.          TabIndex        =   11
  208.          Top             =   48
  209.          Width           =   1212
  210.       End
  211.       Begin VB.CommandButton cmdCancel 
  212.          Caption         =   "&Cancel"
  213.          BeginProperty Font 
  214.             Name            =   "Tahoma"
  215.             Size            =   8.25
  216.             Charset         =   0
  217.             Weight          =   400
  218.             Underline       =   0   'False
  219.             Italic          =   0   'False
  220.             Strikethrough   =   0   'False
  221.          EndProperty
  222.          Height          =   372
  223.          Left            =   2640
  224.          MaskColor       =   &H00000000&
  225.          TabIndex        =   12
  226.          Top             =   48
  227.          Width           =   1212
  228.       End
  229.    End
  230.    Begin VB.PictureBox picFldHdr 
  231.       Appearance      =   0  'Flat
  232.       BorderStyle     =   0  'None
  233.       ForeColor       =   &H80000008&
  234.       Height          =   240
  235.       Left            =   0
  236.       ScaleHeight     =   240
  237.       ScaleMode       =   0  'User
  238.       ScaleWidth      =   14948.92
  239.       TabIndex        =   18
  240.       TabStop         =   0   'False
  241.       Top             =   840
  242.       Width           =   14946
  243.       Begin VB.Label lblFieldValue 
  244.          Caption         =   " Value (F4=Zoom)"
  245.          BeginProperty Font 
  246.             Name            =   "Tahoma"
  247.             Size            =   8.25
  248.             Charset         =   0
  249.             Weight          =   400
  250.             Underline       =   0   'False
  251.             Italic          =   0   'False
  252.             Strikethrough   =   0   'False
  253.          EndProperty
  254.          Height          =   255
  255.          Left            =   1680
  256.          TabIndex        =   20
  257.          Top             =   0
  258.          Width           =   2295
  259.       End
  260.       Begin VB.Label lblFieldHdr 
  261.          Caption         =   "Field Name:"
  262.          BeginProperty Font 
  263.             Name            =   "Tahoma"
  264.             Size            =   8.25
  265.             Charset         =   0
  266.             Weight          =   400
  267.             Underline       =   0   'False
  268.             Italic          =   0   'False
  269.             Strikethrough   =   0   'False
  270.          EndProperty
  271.          Height          =   252
  272.          Left            =   120
  273.          TabIndex        =   19
  274.          Top             =   0
  275.          Width           =   1212
  276.       End
  277.    End
  278.    Begin VB.PictureBox picMoveButtons 
  279.       Align           =   2  'Align Bottom
  280.       Appearance      =   0  'Flat
  281.       BorderStyle     =   0  'None
  282.       ForeColor       =   &H80000008&
  283.       Height          =   288
  284.       Left            =   0
  285.       ScaleHeight     =   298.153
  286.       ScaleMode       =   0  'User
  287.       ScaleWidth      =   5493.878
  288.       TabIndex        =   17
  289.       TabStop         =   0   'False
  290.       Top             =   3465
  291.       Width           =   5484
  292.       Begin VB.HScrollBar hsclCurrRow 
  293.          Height          =   255
  294.          Left            =   0
  295.          Max             =   100
  296.          TabIndex        =   9
  297.          Top             =   29
  298.          Width           =   2895
  299.       End
  300.       Begin VB.Label lblStatus 
  301.          Height          =   255
  302.          Left            =   3000
  303.          TabIndex        =   21
  304.          Top             =   38
  305.          Width           =   1695
  306.       End
  307.    End
  308.    Begin VB.VScrollBar vsbScrollBar 
  309.       Height          =   2250
  310.       LargeChange     =   3000
  311.       Left            =   5040
  312.       SmallChange     =   300
  313.       TabIndex        =   10
  314.       Top             =   1080
  315.       Visible         =   0   'False
  316.       Width           =   255
  317.    End
  318.    Begin VB.PictureBox picFields 
  319.       Appearance      =   0  'Flat
  320.       BorderStyle     =   0  'None
  321.       ForeColor       =   &H80000008&
  322.       Height          =   375
  323.       Left            =   120
  324.       ScaleHeight     =   372
  325.       ScaleMode       =   0  'User
  326.       ScaleWidth      =   4812
  327.       TabIndex        =   15
  328.       TabStop         =   0   'False
  329.       Top             =   1080
  330.       Width           =   4815
  331.       Begin VB.TextBox txtFieldData 
  332.          BackColor       =   &H00FFFFFF&
  333.          DataSource      =   "Data1"
  334.          BeginProperty Font 
  335.             Name            =   "Tahoma"
  336.             Size            =   8.25
  337.             Charset         =   0
  338.             Weight          =   400
  339.             Underline       =   0   'False
  340.             Italic          =   0   'False
  341.             Strikethrough   =   0   'False
  342.          EndProperty
  343.          ForeColor       =   &H00000000&
  344.          Height          =   288
  345.          Index           =   0
  346.          Left            =   1560
  347.          TabIndex        =   0
  348.          Top             =   0
  349.          Visible         =   0   'False
  350.          Width           =   3252
  351.       End
  352.       Begin VB.Label lblFieldName 
  353.          BeginProperty Font 
  354.             Name            =   "Tahoma"
  355.             Size            =   8.25
  356.             Charset         =   0
  357.             Weight          =   400
  358.             Underline       =   0   'False
  359.             Italic          =   0   'False
  360.             Strikethrough   =   0   'False
  361.          EndProperty
  362.          ForeColor       =   &H00000000&
  363.          Height          =   252
  364.          Index           =   0
  365.          Left            =   0
  366.          TabIndex        =   16
  367.          Top             =   60
  368.          Visible         =   0   'False
  369.          Width           =   1572
  370.       End
  371.    End
  372. Attribute VB_Name = "frmDynaSnap"
  373. Attribute VB_GlobalNameSpace = False
  374. Attribute VB_Creatable = False
  375. Attribute VB_PredeclaredId = True
  376. Attribute VB_Exposed = False
  377. Option Explicit
  378. '>>>>>>>>>>>>>>>>>>>>>>>>
  379. Const BUTTON1 = "&Add"
  380. Const BUTTON2 = "&Edit"
  381. Const BUTTON3 = "&Delete"
  382. Const BUTTON4 = "&Close"
  383. Const BUTTON5 = "&Sort"
  384. Const BUTTON6 = "F&ilter"
  385. Const BUTTON7 = "&Move"
  386. Const BUTTON8 = "&Find"
  387. Const BUTTON9 = "&Cancel"
  388. Const BUTTON10 = "&Update"
  389. Const Label1 = "Field Name:"
  390. Const Label2 = "Value (F4=Zoom)"
  391. Const MSG1 = "Add record"
  392. Const MSG2 = "Enter number of Rows to Move:"
  393. Const MSG3 = "(Use negative value to move backwards)"
  394. Const MSG4 = "Field Length Exceeded, Data Truncated!"
  395. Const MSG5 = "Delete Current Record?"
  396. Const MSG6 = "Edit record"
  397. Const MSG7 = "Enter Filter Expression:"
  398. Const MSG8 = "Setting New Filter"
  399. Const MSG9 = "Enter Search Parameters"
  400. Const MSG10 = "Searching for New Record"
  401. Const MSG11 = "Record Not Found"
  402. Const MSG12 = "Resizing Form"
  403. Const MSG13 = "Enter Sort Column:"
  404. Const MSG14 = "Setting New Sort Order"
  405. '>>>>>>>>>>>>>>>>>>>>>>>>
  406. 'form variables
  407. Public mrsFormRecordset As Recordset
  408. Dim msTableName As String      'form recordset table name
  409. Dim mvBookMark As Variant       'form bookmark
  410. Dim mbNotFound As Integer      'used by find function
  411. Dim mbEditFlag As Integer      'edit mode
  412. Dim mbAddNewFlag As Integer    'add mode
  413. Dim mbDataChanged As Integer   'field data dirty flag
  414. Dim mfrmFind As New frmFindForm      'find form instance
  415. Dim mlNumRows As Long          'total rows in recordset
  416. Private Sub cmdAdd_Click()
  417.   On Error GoTo AddErr
  418.   'set the mode
  419.   mrsFormRecordset.AddNew
  420.   lblStatus.Caption = MSG1
  421.   mbAddNewFlag = True
  422.   If mrsFormRecordset.RecordCount > 0 Then
  423.     mvBookMark = mrsFormRecordset.Bookmark
  424.   Else
  425.     mvBookMark = vbNullString
  426.   End If
  427.   picChangeButtons.Visible = True
  428.   picViewButtons.Visible = False
  429.   hsclCurrRow.Enabled = False
  430.   ClearDataFields Me, mrsFormRecordset.Fields.Count
  431.   txtFieldData(0).SetFocus
  432.   mbDataChanged = False
  433.   Exit Sub
  434. AddErr:
  435.   ShowError
  436. End Sub
  437. Private Sub cmdCancel_Click()
  438.    On Error Resume Next
  439.    picChangeButtons.Visible = False
  440.    picViewButtons.Visible = True
  441.    hsclCurrRow.Enabled = True
  442.    mbEditFlag = False
  443.    mbAddNewFlag = False
  444.    mrsFormRecordset.CancelUpdate
  445.    DBEngine.Idle dbFreeLocks
  446.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  447.    mbDataChanged = False
  448. End Sub
  449. Private Sub cmdMove_Click()
  450.   On Error GoTo MVErr
  451.   Dim sBookMark As String
  452.   Dim sRows As String
  453.   Dim lRows As Long
  454.   sRows = InputBox(MSG2 & vbCrLf & MSG3)
  455.   If Len(sRows) = 0 Then Exit Sub
  456.   lRows = CLng(sRows)
  457.   mrsFormRecordset.Move lRows
  458.   'check to see if they moved past the bounds of the recordset
  459.   If mrsFormRecordset.EOF Then
  460.     mrsFormRecordset.MoveLast
  461.   ElseIf mrsFormRecordset.BOF Then
  462.     mrsFormRecordset.MoveFirst
  463.   End If
  464.   sBookMark = mrsFormRecordset.Bookmark  'save the new position
  465.   'now we need to reposition the scrollbar to reflect the move
  466.   If mlNumRows > 32767 Then
  467.     hsclCurrRow.Value = (mrsFormRecordset.PercentPosition * 32767) / 100 + 1
  468.   ElseIf mlNumRows > 99 Then
  469.     hsclCurrRow.Value = (mrsFormRecordset.PercentPosition * mlNumRows) / 100 + 1
  470.   Else
  471.     hsclCurrRow.Value = mrsFormRecordset.PercentPosition
  472.   End If
  473.   mrsFormRecordset.Bookmark = sBookMark
  474.   Exit Sub
  475. MVErr:
  476.   ShowError
  477. End Sub
  478. Private Sub hsclCurrRow_Change()
  479.   On Error GoTo SCRErr
  480.   Static nPrevVal As Integer
  481.   Dim rsTmp As Recordset
  482.   'check for new rows
  483.   On Error Resume Next
  484.   Set rsTmp = mrsFormRecordset.Clone()
  485.   rsTmp.MoveNext
  486.   If mrsFormRecordset.RecordCount > mlNumRows Then
  487.     mlNumRows = mrsFormRecordset.RecordCount
  488.     SetScrollBar
  489.   End If
  490.   On Error GoTo SCRErr
  491.   'based on number of rows, there is different logic needed
  492.   'to set the current position in the recordset
  493.   If mlNumRows > 0 Then
  494.     If mlNumRows > 99 Then   '32767 Then
  495.       'if there are > 32767 we need to use the move methods because
  496.       'the scrollbar is limited to 32767 so if we didn't apply this
  497.       'logic, it would be impossible to get to every record on a
  498.       'small change of the scrollbar
  499.       If hsclCurrRow.Value - nPrevVal = 1 Then
  500.         mrsFormRecordset.MoveNext
  501.       ElseIf hsclCurrRow.Value - nPrevVal = -1 Then
  502.         mrsFormRecordset.MovePrevious
  503.       Else
  504.         If mlNumRows > 32767 Then
  505.           mrsFormRecordset.PercentPosition = (hsclCurrRow.Value / 32767) * 100 + 0.005
  506.         Else
  507.           mrsFormRecordset.PercentPosition = (hsclCurrRow.Value / mlNumRows) * 100 + 0.005
  508.         End If
  509.       End If
  510.       nPrevVal = hsclCurrRow.Value
  511. '    ElseIf mlNumRows > 99 Then
  512. '      'need to calculate the position when there are > 99 recs
  513. '      mrsFormRecordset.PercentPosition = (hsclCurrRow.Value / mlNumRows) * 100 + 0.005
  514.     Else
  515.       mrsFormRecordset.PercentPosition = hsclCurrRow.Value
  516.     End If
  517.   End If
  518.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  519.   mbDataChanged = False
  520.   Screen.MousePointer = vbDefault
  521.   MsgBar vbNullString, False
  522.   Exit Sub
  523. SCRErr:
  524.   ShowError
  525. End Sub
  526. Private Sub txtFieldData_Change(Index As Integer)
  527.   'just set the flag if data is changed
  528.   'it gets reset to false when a new record is displayed
  529.   mbDataChanged = True
  530. End Sub
  531. Private Sub txtFieldData_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  532.   If KeyCode = &H73 Then   'F4
  533.     lblFieldName_DblClick Index
  534.   ElseIf KeyCode = 34 And vsbScrollBar.Visible Then
  535.     'pagedown with > 10 fields
  536.     vsbScrollBar.Value = vsbScrollBar.Value - 3000
  537.   ElseIf KeyCode = 33 And vsbScrollBar.Visible Then
  538.     'pageup with > 10 fields
  539.     vsbScrollBar.Value = vsbScrollBar.Value + 3000
  540.   End If
  541. End Sub
  542. Private Sub txtFieldData_KeyPress(Index As Integer, KeyAscii As Integer)
  543.   'only allow return when in edit of add mode
  544.   If mbEditFlag Or mbAddNewFlag Then
  545.     If KeyAscii = 13 Then
  546.       KeyAscii = 0
  547.       SendKeys "{Tab}"
  548.     End If
  549.   'throw away the keystrokes if not in add or edit mode
  550.   ElseIf mbEditFlag = False And mbAddNewFlag = False Then
  551.     KeyAscii = 0
  552.   End If
  553. End Sub
  554. Private Sub txtFieldData_LostFocus(Index As Integer)
  555.   On Error GoTo FldDataErr
  556.   If mbDataChanged Then
  557.     'store the data in the field
  558.     mrsFormRecordset(Index) = txtFieldData(Index)
  559.   End If
  560.   'reset for valid or error condition
  561.   mbDataChanged = False
  562.   Exit Sub
  563. FldDataErr:
  564.   'reset for valid or error condition
  565.   mbDataChanged = False
  566.   ShowError
  567. End Sub
  568. Private Sub lblFieldName_DblClick(Index As Integer)
  569.   On Error GoTo ZoomErr
  570.   If mrsFormRecordset(Index).Type = dbText Or mrsFormRecordset(Index).Type = dbMemo Then
  571.      If mrsFormRecordset(Index).Type = dbText Then
  572.        gsZoomData = txtFieldData(Index).Text
  573.      ElseIf mrsFormRecordset(Index).FieldSize() < gnGETCHUNK_CUTOFF Then
  574.        gsZoomData = txtFieldData(Index).Text
  575.      Else
  576.        'add the rest of the field data with getchunk
  577.        MsgBar "Getting Memo Field Data", True
  578.        Screen.MousePointer = vbHourglass
  579.        gsZoomData = txtFieldData(Index).Text & _
  580.          StripNonAscii(mrsFormRecordset(Index).GetChunk(gnGETCHUNK_CUTOFF, gnMAX_MEMO_SIZE))
  581.        Screen.MousePointer = vbDefault
  582.        MsgBar vbNullString, False
  583.      End If
  584.      frmZoom.Caption = Mid(lblFieldName(Index).Caption, 1, Len(lblFieldName(Index).Caption) - 1)
  585.      If mbAddNewFlag Or mbEditFlag Then
  586.        frmZoom.cmdSave.Visible = True
  587.        frmZoom.cmdCloseNoSave.Visible = True
  588.      Else
  589.        frmZoom.cmdClose.Visible = True
  590.      End If
  591.      If mrsFormRecordset(Index).Type = dbText Then
  592.        frmZoom.txtZoomData.Text = gsZoomData
  593.        frmZoom.Height = 1125
  594.      Else
  595.        frmZoom.txtMemo.Text = gsZoomData
  596.        frmZoom.txtMemo.Visible = True
  597.        frmZoom.txtZoomData.Visible = False
  598.        frmZoom.Height = 2205
  599.      End If
  600.      frmZoom.Show vbModal
  601.      If (mbAddNewFlag Or mbEditFlag) And gsZoomData <> "__CANCELLED__" Then
  602.        If mrsFormRecordset(Index).Type = dbText And Len(gsZoomData) > mrsFormRecordset(Index).Size Then
  603.          Beep
  604.          MsgBox MSG4, 48
  605.          txtFieldData(Index).Text = Mid(gsZoomData, 1, mrsFormRecordset(Index).Size)
  606.        Else
  607.          txtFieldData(Index).Text = gsZoomData
  608.        End If
  609.        mrsFormRecordset(Index) = txtFieldData(Index).Text
  610.        mbDataChanged = False
  611.      End If
  612.   End If
  613.   Exit Sub
  614. ZoomErr:
  615.   ShowError
  616. End Sub
  617. Private Sub cmdClose_Click()
  618.   DBEngine.Idle dbFreeLocks
  619.   Unload Me
  620. End Sub
  621. Private Sub vsbScrollBar_Change()
  622.   Dim nTop As Integer
  623.   nTop = vsbScrollBar.Value
  624.   If (nTop - 1080) Mod gnCTLARRAYHEIGHT = 0 Then
  625.     picFields.Top = nTop
  626.   Else
  627.     picFields.Top = ((nTop - 1080) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + 1080
  628.   End If
  629. End Sub
  630. Private Sub cmdDelete_Click()
  631.   On Error GoTo DelRecErr
  632.   If MsgBox(MSG5, vbYesNo + vbQuestion) = vbYes Then
  633.     mrsFormRecordset.Delete
  634.     If gbTransPending Then gbDBChanged = True
  635.     If mrsFormRecordset.EOF = False Then
  636.       'see if we can move to the next record
  637.       mrsFormRecordset.MoveNext
  638.       If mrsFormRecordset.EOF And (mrsFormRecordset.RecordCount > 0) Then
  639.         'must've been the last record so we can't move next
  640.         mrsFormRecordset.MoveLast
  641.       End If
  642.     End If
  643.     mlNumRows = mlNumRows - 1
  644.     SetScrollBar
  645.     mlNumRows = mrsFormRecordset.RecordCount
  646.     DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  647.     mbDataChanged = False
  648.   End If
  649.   Exit Sub
  650. DelRecErr:
  651.   ShowError
  652. End Sub
  653. Private Sub cmdEdit_Click()
  654.    On Error GoTo EditErr
  655.   Dim nDelay As Long
  656.   Dim nRetryCnt As Integer
  657.   Screen.MousePointer = vbHourglass
  658. RetryEdit:
  659.    mrsFormRecordset.Edit
  660.    lblStatus.Caption = MSG6
  661.    mbEditFlag = True
  662.    txtFieldData(0).SetFocus
  663.    mvBookMark = mrsFormRecordset.Bookmark
  664.    picChangeButtons.Visible = True
  665.    picViewButtons.Visible = False
  666.    hsclCurrRow.Enabled = False
  667.    Screen.MousePointer = vbDefault
  668.    Exit Sub
  669. EditErr:
  670.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  671.     nRetryCnt = nRetryCnt + 1
  672.     DBEngine.Idle dbFreeLocks
  673.     'Wait gnMUDelay seconds
  674.     nDelay = Timer
  675.     While Timer - nDelay < gnMUDelay
  676.       'do nothing
  677.     Wend
  678.     Resume RetryEdit
  679.   Else
  680.     ShowError
  681.   End If
  682. End Sub
  683. Private Sub cmdFilter_Click()
  684.   On Error GoTo FilterErr
  685.   Dim sBookMark As String
  686.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  687.   Dim sFilterStr As String
  688.   If mrsFormRecordset.RecordCount = 0 Then Exit Sub
  689.   sBookMark = mrsFormRecordset.Bookmark        'save the bookmark
  690.   Set recRecordset1 = mrsFormRecordset            'save the recordset
  691.   sFilterStr = InputBox(MSG7)
  692.   If Len(sFilterStr) = 0 Then Exit Sub
  693.   Screen.MousePointer = vbHourglass
  694.   MsgBar MSG8, True
  695.   mrsFormRecordset.Filter = sFilterStr
  696.   Set recRecordset2 = mrsFormRecordset.OpenRecordset(mrsFormRecordset.Type) 'establish the filter
  697.   'force population to get an accurate recordcount
  698.   recRecordset2.MoveLast
  699.   recRecordset2.MoveFirst
  700.   Set mrsFormRecordset = recRecordset2            'assign back to original recordset object
  701.   'everything must be okay so redisplay form on 1st record
  702.   mlNumRows = mrsFormRecordset.RecordCount
  703.   SetScrollBar
  704.   hsclCurrRow.Value = 0
  705.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  706.   mbDataChanged = False
  707.   Screen.MousePointer = vbDefault
  708.   MsgBar vbNullString, False
  709.   Exit Sub
  710. FilterRecover:
  711.   On Error Resume Next
  712.   Set mrsFormRecordset = recRecordset1            're-assign back to original
  713.   mrsFormRecordset.Bookmark = sBookMark           'go back to original record
  714.   Exit Sub
  715. FilterErr:
  716.   ShowError
  717.   Resume FilterRecover
  718. End Sub
  719. Private Sub cmdFind_Click()
  720.   On Error GoTo FindErr
  721.   Dim i As Integer
  722.   Dim sBookMark As String
  723.   Dim sTmp As String
  724.   'load the column names into the find form
  725.   If mfrmFind.lstFields.ListCount = 0 Then
  726.     For i = 0 To mrsFormRecordset.Fields.Count - 1
  727.       mfrmFind.lstFields.AddItem Mid(lblFieldName(i).Caption, 1, Len(lblFieldName(i).Caption) - 1)
  728.     Next
  729.   End If
  730. FindStart:
  731.   'reset the flags
  732.   gbFindFailed = False
  733.   gbFromTableView = False
  734.   mbNotFound = False
  735.   MsgBar MSG9, False
  736.   mfrmFind.Show vbModal
  737.   MsgBar MSG10, True
  738.   If gbFindFailed Then    'find cancelled
  739.     GoTo AfterWhile
  740.   End If
  741.   Screen.MousePointer = vbHourglass
  742.   i = mfrmFind.lstFields.ListIndex
  743.   sBookMark = mrsFormRecordset.Bookmark
  744.   'search for the record
  745.   If mrsFormRecordset(i).Type = dbText Or mrsFormRecordset(i).Type = dbMemo Then
  746.     sTmp = AddBrackets((mrsFormRecordset(i).Name)) & " " & gsFindOp & " '" & gsFindExpr & "'"
  747.   Else
  748.     sTmp = AddBrackets((mrsFormRecordset(i).Name)) + gsFindOp + gsFindExpr
  749.   End If
  750.   Select Case gnFindType
  751.     Case 0
  752.       mrsFormRecordset.FindFirst sTmp
  753.     Case 1
  754.       mrsFormRecordset.FindNext sTmp
  755.     Case 2
  756.       mrsFormRecordset.FindPrevious sTmp
  757.     Case 3
  758.       mrsFormRecordset.FindLast sTmp
  759.   End Select
  760.   mbNotFound = mrsFormRecordset.NoMatch
  761. AfterWhile:
  762.   Screen.MousePointer = vbDefault
  763.   If gbFindFailed Then    'go back to original row
  764.     mrsFormRecordset.Bookmark = sBookMark
  765.   ElseIf mbNotFound Then
  766.     Beep
  767.     MsgBox MSG11, 48
  768.     mrsFormRecordset.Bookmark = sBookMark
  769.     GoTo FindStart
  770.   Else
  771.     sBookMark = mrsFormRecordset.Bookmark  'save the new position
  772.     'now we need to reposition the scrollbar to reflect the move
  773.     If mlNumRows > 99 Then
  774.       hsclCurrRow.Value = (mrsFormRecordset.PercentPosition * mlNumRows) / 100 + 1
  775.     Else
  776.       hsclCurrRow.Value = mrsFormRecordset.PercentPosition
  777.     End If
  778.     mrsFormRecordset.Bookmark = sBookMark
  779.   End If
  780.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  781.   mbDataChanged = False
  782.   MsgBar vbNullString, False
  783.   Exit Sub
  784. FindErr:
  785.   Screen.MousePointer = vbDefault
  786.   If Err <> gnEOF_ERR Then
  787.     ShowError
  788.   Else
  789.     mbNotFound = True
  790.     Resume Next
  791.   End If
  792. End Sub
  793. Private Sub Form_Load()
  794.   Dim sTmp As String             'temp recordset name string
  795.   Dim nFieldType As Integer      'field type of current field
  796.   Dim i As Integer, j As Integer 'indexes
  797.   On Error GoTo DynasetErr
  798.   cmdAdd.Caption = BUTTON1
  799.   cmdEdit.Caption = BUTTON2
  800.   cmdDelete.Caption = BUTTON3
  801.   cmdClose.Caption = BUTTON4
  802.   cmdSort.Caption = BUTTON5
  803.   cmdFilter.Caption = BUTTON6
  804.   cmdMove.Caption = BUTTON7
  805.   cmdFind.Caption = BUTTON8
  806.   cmdCancel.Caption = BUTTON9
  807.   cmdUpdate.Caption = BUTTON10
  808.   lblFieldHdr.Caption = Label1
  809.   lblFieldValue.Caption = Label2
  810.   'mrsFormRecordset is a public module level variable
  811.   'that must get set prior to 'Show'ing this form
  812.   'set the locking type (comment out for standalone use)
  813.   If gsDataType = gsMSACCESS And mrsFormRecordset.Type <> dbOpenSnapshot Then
  814.     mrsFormRecordset.LockEdits = gnMULocking
  815.   End If
  816.   'get the row count
  817.   With mrsFormRecordset
  818.     If .RecordCount > 0 Then
  819.       'move next, then previous to get recordcount
  820.       .MoveNext
  821.       .MovePrevious
  822.     End If
  823.     mlNumRows = .RecordCount
  824.   End With
  825.   SetScrollBar
  826.   'load the controls on the recordset form
  827.   lblFieldName(0).Visible = True
  828.   txtFieldData(0).Visible = True
  829.   nFieldType = mrsFormRecordset(0).Type
  830.   txtFieldData(0).Width = GetFieldWidth(nFieldType)
  831.   If nFieldType = dbText Then txtFieldData(0).MaxLength = mrsFormRecordset(0).Size
  832.   txtFieldData(0).TabIndex = 0
  833.   For i = 1 To mrsFormRecordset.Fields.Count - 1
  834.     picFields.Height = picFields.Height + gnCTLARRAYHEIGHT
  835.     Load lblFieldName(i)
  836.     lblFieldName(i).Top = lblFieldName(i - 1).Top + gnCTLARRAYHEIGHT
  837.     lblFieldName(i).Visible = True
  838.     Load txtFieldData(i)
  839.     txtFieldData(i).Top = txtFieldData(i - 1).Top + gnCTLARRAYHEIGHT
  840.     txtFieldData(i).Visible = True
  841.     nFieldType = mrsFormRecordset.Fields(i).Type
  842.     txtFieldData(i).Width = GetFieldWidth(nFieldType)
  843.     If nFieldType = dbText Then txtFieldData(i).MaxLength = mrsFormRecordset(i).Size
  844.     txtFieldData(i).TabIndex = i
  845.   Next
  846.   'resize main window
  847.   Me.Width = 5580
  848.   If i <= 10 Then
  849.     Me.Height = ((i + 1) * gnCTLARRAYHEIGHT) + 1600
  850.   Else
  851.     Me.Height = 4368
  852.     Me.Width = Me.Width + 260
  853.     vsbScrollBar.Visible = True
  854.     vsbScrollBar.Min = 1080
  855.     vsbScrollBar.Max = 1080 - (i * gnCTLARRAYHEIGHT) + 2240
  856.   End If
  857.   'display the field names
  858.   For i = 0 To mrsFormRecordset.Fields.Count - 1
  859.     lblFieldName(i).Caption = mrsFormRecordset(i).Name & ":"
  860.   Next
  861.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  862.   mbDataChanged = False
  863.   Me.Left = 1000
  864.   Me.Top = 1000
  865.   MsgBar vbNullString, False
  866.   Exit Sub
  867. DynasetErr:
  868.   ShowError
  869.   Unload Me
  870. End Sub
  871. Private Sub Form_Resize()
  872.   On Error Resume Next
  873.   Dim nHeight As Integer
  874.   Dim i As Integer
  875.   Dim nTotWidth As Integer
  876.   Const nHeightFactor = 1420
  877.   If WindowState <> 1 Then   'not minimized
  878.     MsgBar MSG12, True
  879.     'make sure the form is lined up on a field
  880.     nHeight = Height
  881.     If (nHeight - nHeightFactor) Mod gnCTLARRAYHEIGHT <> 0 Then
  882.       Me.Height = ((nHeight - nHeightFactor) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + nHeightFactor
  883.     End If
  884.     'resize the status bar
  885.     picMoveButtons.Top = Me.Height - 650
  886.     'resize the scrollbar
  887.     vsbScrollBar.Height = picMoveButtons.Top - (picViewButtons.Top - picFldHdr.Height) - 1320
  888.     vsbScrollBar.Left = Me.Width - 360
  889.     If mrsFormRecordset.Fields.Count > 10 Then
  890.       picFields.Width = Me.Width - 260
  891.       nTotWidth = vsbScrollBar.Left - 20
  892.     Else
  893.       picFields.Width = Me.Width - 20
  894.       nTotWidth = Me.Width - 50
  895.     End If
  896.     picFldHdr.Width = Me.Width - 20
  897.     'widen the fields if possible
  898.     For i = 0 To mrsFormRecordset.Fields.Count - 1
  899.       lblFieldName(i).Width = 0.3 * nTotWidth
  900.       txtFieldData(i).Left = lblFieldName(i).Width + 20
  901.       If mrsFormRecordset(i).Type = dbText Or mrsFormRecordset(i).Type = dbMemo Then
  902.         txtFieldData(i).Width = 0.7 * nTotWidth - 250
  903.       End If
  904.     Next
  905.     lblFieldValue.Left = txtFieldData(0).Left
  906.     hsclCurrRow.Width = picMoveButtons.Width \ 2
  907.     lblStatus.Width = picMoveButtons.Width \ 2
  908.     lblStatus.Left = hsclCurrRow.Width + 10
  909.   End If
  910.   MsgBar vbNullString, False
  911. End Sub
  912. Private Sub Form_Unload(Cancel As Integer)
  913.   On Error Resume Next
  914.   Unload mfrmFind   'get rid of attached find form
  915.   mrsFormRecordset.Close          'close the form recordset
  916.   DBEngine.Idle dbFreeLocks
  917.   MsgBar vbNullString, False
  918. End Sub
  919. Private Sub cmdSort_Click()
  920.   On Error GoTo SortErr
  921.   Dim sBookMark As String
  922.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  923.   Dim SortStr As String
  924.   If mrsFormRecordset.RecordCount = 0 Then Exit Sub
  925.   sBookMark = mrsFormRecordset.Bookmark        'save the bookmark
  926.   Set recRecordset1 = mrsFormRecordset            'save the recordset
  927.   SortStr = InputBox(MSG13)
  928.   If Len(SortStr) = 0 Then Exit Sub
  929.   Screen.MousePointer = vbHourglass
  930.   MsgBar MSG14, True
  931.   mrsFormRecordset.Sort = SortStr
  932.   'establish the Sort
  933.   Set recRecordset2 = mrsFormRecordset.OpenRecordset(mrsFormRecordset.Type)
  934.   Set mrsFormRecordset = recRecordset2            'assign back to original recordset object
  935.   'everything must be okay so redisplay form on 1st record
  936.   mlNumRows = mrsFormRecordset.RecordCount
  937.   hsclCurrRow.Value = 0
  938.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  939.   mbDataChanged = False
  940.   Screen.MousePointer = vbDefault
  941.   MsgBar vbNullString, False
  942.   Exit Sub
  943. SortRecover:
  944.   On Error Resume Next
  945.   Set mrsFormRecordset = recRecordset1            're-assign back to original
  946.   mrsFormRecordset.Bookmark = sBookMark        'go back to original record
  947.   Exit Sub
  948. SortErr:
  949.   ShowError
  950.   Resume SortRecover
  951. End Sub
  952. Private Sub cmdUpdate_Click()
  953.   On Error GoTo UpdateErr
  954.   Dim nDelay As Long
  955.   Dim nRetryCnt As Integer
  956.   Screen.MousePointer = vbHourglass
  957. RetryUpd:
  958.   mrsFormRecordset.Update
  959.   If gbTransPending Then gbDBChanged = True
  960.   If mbAddNewFlag Then
  961.     mlNumRows = mlNumRows + 1
  962.     SetScrollBar
  963.     'move to the new record
  964.     mrsFormRecordset.Bookmark = mrsFormRecordset.LastModified
  965.   End If
  966.   picChangeButtons.Visible = False
  967.   picViewButtons.Visible = True
  968.   hsclCurrRow.Enabled = True
  969.   mbEditFlag = False
  970.   mbAddNewFlag = False
  971.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  972.   mbDataChanged = False
  973.   DBEngine.Idle dbFreeLocks
  974.   Screen.MousePointer = vbDefault
  975.   Exit Sub
  976. UpdateErr:
  977.   'check for locked error
  978.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  979.     nRetryCnt = nRetryCnt + 1
  980.     mrsFormRecordset.Bookmark = mrsFormRecordset.Bookmark   'Cancel the update
  981.     DBEngine.Idle dbFreeLocks
  982.     nDelay = Timer
  983.     'Wait gnMUDelay seconds
  984.     While Timer - nDelay < gnMUDelay
  985.       'do nothing
  986.     Wend
  987.     Resume RetryUpd
  988.   Else
  989.     ShowError
  990.   End If
  991. End Sub
  992. Private Sub SetScrollBar()
  993.   On Error Resume Next
  994.   If mlNumRows < 2 Then
  995.     hsclCurrRow.Max = 100
  996.     hsclCurrRow.SmallChange = 1 '00
  997.     hsclCurrRow.LargeChange = 100
  998.   ElseIf mlNumRows > 32767 Then
  999.     hsclCurrRow.Max = 32767
  1000.     hsclCurrRow.SmallChange = 1
  1001.     hsclCurrRow.LargeChange = 1000
  1002.   ElseIf mlNumRows > 99 Then
  1003.     hsclCurrRow.Max = mlNumRows
  1004.     hsclCurrRow.SmallChange = 1
  1005.     hsclCurrRow.LargeChange = mlNumRows \ 20
  1006.   Else
  1007.     'must be between 2 and 100
  1008.     hsclCurrRow.Max = 100
  1009.     hsclCurrRow.SmallChange = 100 \ (mlNumRows - 1)
  1010.     hsclCurrRow.LargeChange = (100 \ (mlNumRows - 1)) * 10
  1011.   End If
  1012.   'move off, then back on to fix flashing bar
  1013.   txtFieldData(0).SetFocus
  1014.   hsclCurrRow.SetFocus
  1015. End Sub
  1016.